package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.OpinionMapper;
import com.lanyan.system.domain.Opinion;
import com.lanyan.system.domain.vo.OpinionVo;
import com.lanyan.system.service.IOpinionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 投诉建议Service业务层处理
 *
 * @author lanyan
 * @date 2024-11-26
 */
@Service
public class OpinionServiceImpl  extends ServiceImpl<OpinionMapper,Opinion> implements IOpinionService

{
    @Autowired
    private OpinionMapper opinionMapper;

    /**
     * 查询投诉建议
     *
     * @param opinionId 投诉建议主键
     * @return 投诉建议
     */
    @Override
    public Opinion selectOpinionByOpinionId(Long opinionId)
    {
        return this.getById(opinionId);
    }

    /**
     * 查询投诉建议Vo列表
     *
     * @param opinion 投诉建议
     * @return 投诉建议
     */
    @Override
    public List<OpinionVo> selectOpinionVoList(Opinion opinion)
    {
        return selectOpinionList(opinion)
                .stream()
                .map(x -> (OpinionVo)x)
                .collect(Collectors.toList());
    }
    /**
     * 查询投诉建议列表
     *
     * @param opinion 投诉建议
     * @return 投诉建议
     */
    @Override
    public List<Opinion> selectOpinionList(Opinion opinion)
    {
        LambdaQueryChainWrapper<Opinion> wrapper = this.lambdaQuery().eq(Opinion::getDelFlag,"0");
        if (opinion.getAccountId() != null) {
            wrapper.eq(Opinion::getAccountId, opinion.getAccountId());
        }
        if (StringUtils.isNotEmpty(opinion.getContent())) {
            wrapper.eq(Opinion::getContent, opinion.getContent());
        }
        if (StringUtils.isNotEmpty(opinion.getImg())) {
            wrapper.eq(Opinion::getImg, opinion.getImg());
        }
        if (StringUtils.isNotEmpty(opinion.getPhone())) {
            wrapper.eq(Opinion::getPhone, opinion.getPhone());
        }
        if (StringUtils.isNotEmpty(opinion.getFeedback())) {
            wrapper.eq(Opinion::getFeedback, opinion.getFeedback());
        }
        if (StringUtils.isNotEmpty(opinion.getType())) {
            if (StringUtils.equals(opinion.getType(),"0")){
                wrapper.isNull(OpinionVo::getFeedback);
            }else {
                wrapper.isNotNull(OpinionVo::getFeedback);
            }
        }
        return wrapper.list();
    }

        /**
         * 新增投诉建议
         *
         * @param opinion 投诉建议
         * @return 结果
         */
    @Override
        public boolean insertOpinion(Opinion opinion)
        {
                    opinion.setCreateTime(DateUtils.getNowDate());
                return this.save(opinion);
        }

        /**
         * 修改投诉建议
         *
         * @param opinion 投诉建议
         * @return 结果
         */
    @Override
        public boolean updateOpinion(Opinion opinion)
        {
                    opinion.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(opinion);
        }

        /**
         * 批量删除投诉建议
         *
         * @param opinionIds 需要删除的投诉建议主键
         * @return 结果
         */
    @Override
        public boolean deleteOpinionByOpinionIds(Long[] opinionIds)
        {
            return this.lambdaUpdate().set(Opinion::getDelFlag,"1").in(Opinion::getOpinionId,opinionIds).update();
        }

        /**
         * 删除投诉建议信息
         *
         * @param opinionId 投诉建议主键
         * @return 结果
         */
    @Override
        public boolean deleteOpinionByOpinionId(Long opinionId)
        {
            return this.lambdaUpdate().set(Opinion::getDelFlag,"1").eq(Opinion::getOpinionId,opinionId).update();
        }
    }
